from django.contrib import admin
from .models import Author, Genre, Book, BookInstance, BookRating, BookReview, BookLike

# 注册 Genre
admin.site.register(Genre)

# 自定义 Author 的 admin
class AuthorAdmin(admin.ModelAdmin):
    list_display = ('last_name', 'first_name', 'date_of_birth', 'date_of_death')
    fields = ['first_name', 'last_name', ('date_of_birth', 'date_of_death')]

admin.site.register(Author, AuthorAdmin)

# BookInstance 作为内联
class BooksInstanceInline(admin.TabularInline):
    model = BookInstance

# 自定义 Book 的 admin
class BookAdmin(admin.ModelAdmin):
    list_display = ('title', 'author', 'display_genre')
    inlines = [BooksInstanceInline]

admin.site.register(Book, BookAdmin)

# 自定义 BookInstance 的 admin
@admin.register(BookInstance)
class BookInstanceAdmin(admin.ModelAdmin):
    list_display = ('book', 'status', 'borrower', 'due_back', 'id')
    list_filter = ('status', 'due_back')
    fieldsets = (
        (None, {'fields': ('book', 'imprint', 'id')}),
        ('可用性', {'fields': ('status', 'due_back', 'borrower')}),
    )

admin.site.register(BookRating)
admin.site.register(BookReview)
admin.site.register(BookLike)



